home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / libusg / ftime.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  1KB  |  47 lines

  1. /*
  2.  * Uglix ftime simulation
  3.  */
  4.  
  5. #include <ctype.h>
  6. #include <sys/types.h>
  7. #include <sys/timeb.h>        /* see news/include */
  8. #include <sys/times.h>
  9.  
  10. #define NULL 0
  11. #ifndef HZ
  12. #define HZ 60
  13. #endif
  14.  
  15. /* imports from libc */
  16. extern time_t time();
  17. extern time_t times();            /* only true on Uglix */
  18. extern char *getenv();
  19.  
  20. ftime(tp)
  21. struct timeb *tp;
  22. {
  23.     register char *tz;
  24. #ifdef SANE
  25.     /*
  26.      * Since times() is not required to use the same time base for its
  27.      * return value as time() uses, we can't easily get sub-second resolution.
  28.      */
  29.     struct tms timesbuf;
  30.     register int hz = times(×buf) % HZ;    /* hertz beyond time(0) */
  31.  
  32.     tp->millitm = (hz*1000L)/HZ;
  33. #else
  34.     tp->millitm = 0;
  35. #endif
  36.     tp->time = time(&tp->time);
  37.     tz = getenv("TZ");
  38.     if (tz == NULL)            /* just pick one */
  39.         tz = "EST5EDT";
  40.     while (*tz != '\0' && isascii(*tz) && !isdigit(*tz) && *tz != '-')
  41.         tz++;            /* find hrs from greenwich */
  42.     tp->timezone = atoi(tz) * 60;    /* in minutes */
  43.     while (*tz != '\0' && isascii(*tz) && (isdigit(*tz) || *tz == '-'))
  44.         tz++;            /* find DST, if any */
  45.     tp->dstflag = (*tz != '\0');
  46. }
  47.